<?php 
include_once 'inc/config.inc.php';
include_once 'inc/mysql.inc.php';
include_once 'inc/tool.inc.php';
$link=connect();
if(!$member_id=is_login($link)){
	skip('login.php', 'error', '请登录之后再发帖!');
}
if(isset($_POST['submit'])){
	include 'inc/check_publish.inc.php';
	$_POST=escape($link,$_POST);
	$query="insert into sfk_content(module_id,title,content,time,member_id) values({$_POST['module_id']},'{$_POST['title']}','{$_POST['content']}',now(),{$member_id})";
	execute($link, $query);
	if($link->affected_rows){
		skip($_SERVER['HTTP_REFERER'], 'ok', '发布成功！');
	}else{
		skip($_SERVER["HTTP_REFERER"], 'error', '发布失败，请重试！');
	}
}
$template['title']='帖子发布页';
$template['css']=array('style/public.css','style/publish.css');
?>
<?php include 'inc/header.inc.php'?>
	<div id="position" class="auto">
		 <a href="index.php">首页</a> &gt; 发布帖子
	</div>
	<div id="publish">
		<form method="post">
			<select name="module_id">
				<?php
                if ($_GET['id'] && is_numeric($_GET['id'])) {
                    $where1 = "where id = {$_GET['id']} ";
                } elseif ($_GET['son_id'] && is_numeric($_GET['son_id'])) {
                    $query = "select father_module_id from sfk_son_module where id = {$_GET['son_id']}  limit 1";
                    $father_id = execute($link,$query)->fetch_array();
                    $where1 = "where id = {$father_id['father_module_id']} ";
                    $where2 = "and where id = {$_GET['son_id']}";
                }else {
                    $where1 = '';
                }
				$query="select * from sfk_father_module {$where1} order by sort desc";
				$result_father=execute($link, $query);
				while ($data_father=$result_father->fetch_assoc()){
					echo "<optgroup label='{$data_father['module_name']}'>";
					$query="select * from sfk_son_module where father_module_id={$data_father['id']}  order by sort desc";
					$result_son=execute($link, $query);
					while ($data_son=$result_son->fetch_assoc()){
					    if ($data_son['id'] == $_GET['son_id']) {
                            echo "<option value='{$data_son['id']}' selected=”selected”>{$data_son['module_name']}</option>";
                        } else {
                            echo "<option value='{$data_son['id']}'>{$data_son['module_name']}</option>";
                        }
					}
					echo "</optgroup>";
				}
				?>
			</select>
			<input class="title" placeholder="请输入标题" name="title" type="text" />
			<textarea name="content" class="content"></textarea>
			<input class="publish" type="submit" name="submit" value="" />
			<div style="clear:both;"></div>
		</form>
	</div>
<?php include 'inc/footer.inc.php'?>